package com.stu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.stu.common.R;
import com.stu.mapper.StudentMapper;
import com.stu.mapper.StudentTuiMapper;
import com.stu.pojo.StudentTui;
import com.stu.pojo.vo.StudentDescVo;
import com.stu.service.StudentTuiService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class StudentTuiServiceImpl extends ServiceImpl<StudentTuiMapper, StudentTui>
    implements StudentTuiService {

    @Autowired
    private StudentMapper studentMapper;

    @Transactional
    @Override
    public R tuixue(StudentDescVo studentDescVo) {
        StudentTui studentTui = new StudentTui();
        BeanUtils.copyProperties(studentDescVo,studentTui);
        studentTui.setText(studentDescVo.getDescription());
        // 删除原有数据
        studentMapper.deleteById(studentDescVo.getId());
        // 在退学表添加数据
        this.save(studentTui);
        return R.success("退学完成，已存档！");
    }
}
